
import { Condition, QueryBuilder, QueryType } from 'apijson-builder'
import { pa } from 'element-plus/es/locale'
import { IPage, IPageReq } from '..'
function parseFieldJson(obj:any,fieldName:string) {
    obj[fieldName] = JSON.parse(obj[fieldName])
}
export interface AccessData{
    id:number,
    name:string
}
class AccessService {
    async getList(tableName:string,pageNo = 0,pageSize = 10):Promise<IPage<AccessData>> {
        const query = QueryBuilder.by('Access',2)
        if(tableName != '') {
            query.condition(Condition.by('name','eq',tableName))
        }

            
        const rs = await query.multi(true)
            .page(pageNo,pageSize)
            .send()
        rs.Access.forEach(it => {
            parseFieldJson(it,'get')
            parseFieldJson(it,'gets')
            parseFieldJson(it,'head')
            parseFieldJson(it,'heads')
            parseFieldJson(it,'post')
            parseFieldJson(it,'put')
            parseFieldJson(it,'delete')
        })
        return {
            data:rs.Access,
            total:rs.total,
            size: pageSize,
            current: pageNo
        }
    }
}

export default new AccessService()